<?php

namespace app\api\controller;

use app\common\controller\Api;

/**
 * 课程
 */
class Course extends Api
{
    protected $noNeedLogin = [''];
    protected $noNeedRight = '*';

    /**
     * 列表
     * @param int classify_id
     * @param int recommend
     * @return void
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function lst()
    {
        $classify_id = $this->request->get("classify_id", 0);
        $recommend = $this->request->get("recommend", 0);
        $campus_id = $this->auth->getUser()['campus_id'];
        $where['campus_id'] = $campus_id;
        if ($recommend != 0) {
            $where['recommend'] = $recommend;
        }
        if ($classify_id != 0) {
            $where['classify_id'] = $classify_id;
        }
        $model = new \app\common\model\Course();
        $data = $model
            ->where($where)
            ->where("status", 1)
            ->order("weigh", "desc")
            ->paginate();
        $this->success("列表", $data);
    }

    /**
     * 获取详情
     * @param int $id id
     * @return void
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function info()
    {
        $param = $this->request->get("id");
        $model = new \app\common\model\Course();
        $data = $model
            ->where("id", $param)->find();
        $this->success("", $data);
    }


}